#include <bitgene/bencode.hpp>
#include <fstream>
#include <sstream>

int main(int argc, char *argv[])
{
	if (argc != 2)
	{
		printf("usage: %s filename\n", argv[0]);
		return 1;
	}
	std::ifstream in(argv[1], std::ios::binary);
	in.exceptions(std::ios::failbit);
	bitgene::bencode v1, v2;
	in >> v1;
	size_t c0 = in.tellg();
	std::stringstream ss1, ss2;
	ss1.exceptions(std::ios::failbit);
	ss2.exceptions(std::ios::failbit);
	ss1 << v1;
	ss1 >> v2;
	ss2 << v2;
	std::string s1 = ss1.str(), s2 = ss2.str();
	size_t c1 = s1.size();
	int r = !((s1 == s2) && (c0 == c1));
	if (r == 0)
		printf("test succeed.\n");
	return r;
}
